package com.zsy.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.zsy.service.BBSService;

public class AddKey extends HttpServlet {

	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		try {
			request.setCharacterEncoding("UTF-8");
			String type = request.getParameter("type");
			String key = request.getParameter("keyword");
			BBSService bbss = new BBSService();
			bbss.saveKey(type, key);
			if("0".equals(type)){
				response.sendRedirect("web/showkey?type=0");
			}else{
				response.sendRedirect("web/showkey?type=1");
			}
		} catch (SQLException e) {
			request.getSession().setAttribute("msg", "关键字不能重复添加！");
			response.sendRedirect("web/showkey?type=0");
		}
		

	}

}
